package com.bjtang.fileSync.util;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

public class FileConfig {
	private static final String CONFIG_PATH = "conf/init.config";

	private static final String LOG_CONFIG_PATH = "conf/log4j2.xml";

	public static String getConfigPath() {
		return CONFIG_PATH;
	}

	public static String getLogConfigPath() {
		return LOG_CONFIG_PATH;
	}

	public static String[] readConfig(File file, String[] names) {

		Properties pros = new Properties();
		try {
			String[] newStr = new String[names.length];
			FileReader read = new FileReader(file);
			pros.load(read);
			for (int i = 0; i < names.length; i++) {
				newStr[i] = pros.getProperty(names[i]);
			}
			read.close();
			return newStr;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String readConfig(File file, String name) {
		Properties pros = new Properties();
		try {
			FileReader read = new FileReader(file);
			pros.load(read);
			String property = pros.getProperty(name);
			read.close();
			return property;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String[] readConfig(String path, String[] names) {
		return readConfig(new File(path), names);
	}

	public static String readConfig(String path, String name) {
		return readConfig(new File(path), name);
	}

	public static String readConfig(String name) {
		System.err.println("查询了配置文件"+name);
		return readConfig(CONFIG_PATH, name);
	}

}
